<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>已投项目</title>
    <link rel="stylesheet" type="text/css" href="./css/api.css" />
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/font-awesome.min.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <script type="text/javascript" src="./script/api.js"></script>
    <script type="text/javascript" src="./script/doT.min.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/aui-tab.js" ></script>
    <link rel="stylesheet" type="text/css" href="./css/aui-slide.css" />
    <script type="text/javascript" src="./script/aui-slide.js"></script>
    <script type="text/javascript">
        function closeWin(){
            api.closeToWin({
                name: 'home'
            });
        };
    </script>
</head>
<body>
    <!-- 头部 -->
    <header class="aui-bar aui-bar-nav pos" id="topbar">
        <a class="aui-pull-left aui-btn" onclick="closeWin()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">我的随意享</div>
    </header>
    <div class="header-d"></div>
    <div id="list">
        <div class="loan-list-1-d">
            <ul>
                <li>
                    <div class="loan-list-1-d-t">
                        <p>企业经营贷-0000000-000</p>

                    </div>
                    <div class="loan-list-1-d-l">
                        预期年化利率
                        <p>00.0 <span>%</span></p>
                    </div>
                    <div class="loan-list-1-d-m">
                        <p>金额:0,000.00元</p>
                        <p>时间:0000-00-00</p>
                    </div>
                    <div class="loan-list-1-d-r">
                        <a class="active">提现</a>
                    </div>
                </li>
            </ul>
        </div>
    </div>
</body>
<script type="text/template" id="template">
    {{~it:value:index}}
    <div class="loan-list-1-d">
        <ul>
            <li>
                <div class="loan-list-1-d-t">
                    <p>{{=value.licai_name}}-{{=value.licai_sn}}</p>
                </div>
                <div class="loan-list-1-d-l">
                    预期年化利率
                    <p>{{=value.rate}}<span>%</span></p>
                </div>
                <div class="loan-list-1-d-m">
                    <p>金额:{{=value.money}}元</p>
                    <p>时间:{{=value.create_date}}</p>
                </div>
                {{? value.status == '0'}}
                <div class="loan-list-1-d-r" onclick="withdraw({{=value.id}},{{=value.money}},{{=value.cash}});">
                    <a class="active">提现</a>
                </div>
                {{??}}
                <div class="loan-list-1-d-r">
                    <a>已提</a>
                </div>
                {{?}}
            </li>
        </ul>
    </div>
    {{~}}
</script>
<script type="text/javascript">
   apiready = function(){
    api.addEventListener({
        name: 'keyback'
    }, function(ret, err) {
        closeWin();
    });
    updateData();
    // pullRefresh();
    // pullLoading();
};

    // 更新数据,模板函数
    function updateData(){
        // 进度提示框
        api.showProgress({
            title: '努力加载中...',
            text: '请稍等...',
            modal: false
        });

        var userid = $api.getStorage('userid');
        api.ajax({
            url: webAddress + '/index.php?ctl=app_user_center&act=licai_list',
            method: 'post',
            data: {
                values: {
                    id: userid,
                },
            }
        },function(ret, err){
            if (ret) {
                // var ret = $api.jsonToStr(ret);
                // alert(ret);
                // 关闭下拉刷新控件
                // api.refreshHeaderLoadDone();
                api.hideProgress();
                if (ret.status == 0) {
                    alert(ret.info);
                    return false;
                }else{

                    var data = ret.list;

                    if (data) {
                        // withdrawID = data.id;
                        templateFun(data);
                    }else{
                        var list = $api.byId('list');
                        list.innerHTML = '<div class="login-list-no">没有理财记录</div>';
                    }
                }
            } else {
                alert(err.msg);
        // api.refreshHeaderLoadDone();
        api.hideProgress();
    }
});
    };

    // 模板赋值函数
    function templateFun(data){
        var template = $api.byId('template');
        var dotFn = doT.template(template.innerHTML);
        var html = dotFn(data);
        var user = $api.byId('list');
        $api.html(user, html);
    }

    // 下拉刷新
    function pullRefresh(){
        api.setRefreshHeaderInfo({
            // loadingImg: 'widget://image/refresh.png',
            bgColor: '#ccc',
            textColor: '#fff',
            textDown: '下拉刷新...',
            textUp: '松开刷新...'
        }, function(ret, err) {
            //在这里从服务器加载数据，加载完成后调用api.refreshHeaderLoadDone()方法恢复组件到默认状态
            updateData();
        });
    }

    // 上拉加载
    function pullLoading(){
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 0
            }
        }, function(ret, err){
         updateData();
     });
    }

    function withdraw(withdrawID,money,cash){

        api.openWin({
            name: 'suiyixiang-withdraw',
            url: './suiyixiang-withdraw.html',
            pageParam: {
                withdrawID: withdrawID,
                money:money,
                cash:cash,
            }
        });


        // api.ajax({
        //     url: webAddress + '/index.php?ctl=deal&act=cash_yuebao',
        //     method: 'post',
        //     data: {
        //         values: { 
        //             id: withdrawID,
        //             ajax: 1,
        //         },
        //     }
        // },function(ret, err){
        //     if (ret) {
        //         if (ret.status == 0) {
        //             alert(ret.info);
        //             return false;
        //         } else {
        //             api.toast({
        //                 msg: '提现成功',
        //                 duration: 2000,
        //                 location: 'middle'
        //             });
        //             // 提现成功 跳转资金统计页面
        //             api.openWin({
        //                 name: 'my_fund',
        //                 url: './my-fund.html',
        //                 pageParam: {
        //                     name: 'test'
        //                 }
        //             });
        //         }
        //     } else {
        //         alert(err.msg);
        //     }
        // });
    }

    // 加载状态控件
    function showProgress(){
        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '请稍后...',
            modal: false
        });
    }
</script>
</html>